<!DOCTYPE html>
<html>
<head>
    <title>用户评分</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="description" content="木兰湾管理系统">
    <script type="text/javascript" src="../../static/include/header-css.js"></script>
</head>
<body>
<!--查询条件-->
<div>
    <form id="search-form">
        <div class="weui-cell mulanbay_select-before ">
            <div class="weui-cell__hd" >
                <label class="weui-label">日期</label>
            </div>
            <div class="weui-cell__bd">
                <input class="weui-input" id="endDate" name="endDate" type="text">
            </div>
            <div class="weui-cell__hd" >
                <a href="javascript:showInfoMsg('统计时间段为该日期往前30天，如果此处为空，那么为当前时间到30天前');"><img src="../../static/image/help.png" alt="说明"></img></a>
            </div>
            <div class="weui-cell__hd">
                <a href="javascript:searchData()" class="weui-btn weui-btn_mini weui-btn_primary">查询</a>
            </div>
        </div>
    </form>
    <div class="weui-cell__hd" align="center">
        <label id="totalScore"></label>
        <a href="userScoreStat.html" >(统计)</a>
    </div>
</div>
<!--列表数据显示-->
<div id="dataContent"></div>
<div class="button_sp_area" align="center">
    <a href="javascript:scroll(0,0);" class="weui-btn weui-btn_mini weui-btn_primary">返回顶部</a>
</div>
<br>

<script type="text/javascript" src="../../static/include/footer-js.js"></script>
<script>
    $(function() {
        $("#endDate").calendar({
            //初始值无效
            value: [getNowDateString()],
            dateFormat: 'yyyy-mm-dd',
            onChange: function (p, values, displayValues) {
                if(values!=$('#endDate').val()){
                    searchData();
                }
            }
        });
        var formData={
            endDate : getNowDateString()
        }
        $('#search-form').loadJson(formData);
        searchData();
    });
    function getDivId(id) {
        return 'UserScore'+id;
    }
    function searchData() {
        var para = form2Json('search-form');
        var url='/user/getScoreCompare';
        doAjax(para,url,'GET',false,function(data){
            var html='';
            var totalScore=0;
            var nowData = data.nowData;
            var beforeData = data.beforeData;
            for (var i = 0; i < nowData.length; i++) {
                var rowData =nowData[i];
                html+='<div id="'+getDivId(rowData.id)+'">';
                html+='<div class="weui-form-preview">';
                html+='    <a class="weui-cell  weui-cell_access weui-cell_example" href="javascript:showEdit('+rowData.id+');">\n';
                html+='        <div class="weui-cell__hd"><img src="../../static/image/score.png"></div>\n';
                html+='        <div class="weui-cell__bd">\n';
                html+='<label class="weui-form-preview__label mulanbay-dark-font">'+rowData.name+'</label>';
                html+='        </div>\n';
                html+='        <div class="weui-cell__ft">得分:'+formatScore(rowData.score,beforeData,rowData.scoreConfigId,rowData.maxScore)+'</div>\n';
                html+='    </a>\n';
                html+='    <div class="weui-form-preview__bd">\n';
                html+='        <div class="weui-form-preview__item">\n';
                html+='            <label class="weui-form-preview__label">单项满分</label>\n';
                html+='            <span class="weui-form-preview__value">'+rowData.maxScore+'</span>\n';
                html+='        </div>\n';
                html+='        <div class="weui-form-preview__item">\n';
                html+='            <label class="weui-form-preview__label">统计值</label>\n';
                html+='            <span class="weui-form-preview__value">'+rowData.statValue+'</span>\n';
                html+='        </div>\n';
                html+='        <div class="weui-form-preview__item">\n';
                html+='            <label class="weui-form-preview__label">参考值</label>\n';
                html+='            <span class="weui-form-preview__value">'+rowData.limitValue+'</span>\n';
                html+='        </div>\n';
                html+='        <div class="weui-form-preview__item">\n';
                html+='            <label class="weui-form-preview__label">说明</label>\n';
                html+='            <span class="weui-form-preview__value">'+rowData.remark+'</span>\n';
                html+='        </div>\n';
                html+='    </div>\n';
                html+='</div>\n';
                html+='</div>\n';
                html+='<br>\n';
                totalScore+=nowData[i].score;
            }
            setElementInnerHTML('dataContent',html);
            var totalBeforeScore=0;
            for (var i = 0; i < beforeData.length; i++){
                totalBeforeScore+=beforeData[i].score;
            }
            var ss = totalScore-totalBeforeScore;
            if(ss>0){
                totalScore = totalScore+'<font color="green">(+'+ss+')</font>';
            }else if(ss<0){
                totalScore = totalScore+'<font color="red">(-'+(0-ss)+')</font>';
            }
            setElementInnerHTML('totalScore','<font color="black">总分：'+totalScore+'</font>');
        });
    }
    function formatScore(score,beforeData,scoreConfigId,maxScore) {
        var res = score;
        if(score==maxScore){
            res+='<font color="red">★</font>';
        }
        if(beforeData==null){
            return res;
        }
        var beforeScore=null;
        for (var i = 0; i < beforeData.length; i++){
            if(scoreConfigId==beforeData[i].scoreConfigId){
                beforeScore = beforeData[i].score;
            }
        }
        if(beforeScore!=null){
            var ss = score-beforeScore;
            if(ss>0){
                return res+'<font color="green">(+'+ss+')</font>';
            }else if(ss<0){
                return res+'<font color="red">(-'+(0-ss)+')</font>';
            }else{
                return res;
            }
        }else{
            return res;
        }
    }
</script>
</body>
</html>